/*
 *  System.h
 *  SpaceTrader
 *
 *  Created by Andrew on 10/16/12.
 *  Copyright 2012 The Hex Pistols. All rights reserved.
 *
 */

#pragma once
#include "GuiTools.h"
#include <string>
#include <vector>
#include "Planet.h"
#include "boost/archive/text_oarchive.hpp"
#include "boost/archive/text_iarchive.hpp"
#include <fstream>
#include <boost/serialization/split_member.hpp>

class System {
	
private:
    friend class boost::serialization::access;
	std::string name;
	
	//the system's location in the universe
	int x, y;
    SDL_Surface *icon;	
	std::vector<Planet*> planets;

	
	
    template<class Archive>
    void save(Archive & ar, const unsigned int version) const
    {
        //serialization
        ar & name;
        ar & x;
        ar & y;
        //ar & planets;
        for (unsigned int i = 0; i < planets.size(); i++){
            ar & planets[i];
        }
    }
    template<class Archive>
    void load(Archive & ar, const unsigned int version){
        ar >> name;
        ar >> x;
        ar >> y;
        //ar >> planets;
        unsigned int size = 0;
        if (name == "Argos Rho"){
            size = 3;
        } else if (name == "Armstrong Nebula"){
            size = 5;
        } else {
            size = 5;
        }
        planets = *new std::vector<Planet*>();
        while (planets.size() < size){
            Planet *planet;
            ar >> planet;
            if (planet != NULL){
                planets.push_back(planet);
            }
        }
    }
    BOOST_SERIALIZATION_SPLIT_MEMBER();
    
	
	
	
public:
    System();
	System(std::string, int, int, std::vector<Planet*>, SDL_Surface *);
	System(const System &S);
	~System();
    System& operator=(System &S);
	
	std::string getName();
	
	int getX();
	int getY();
	
	std::vector<Planet*> getPlanets();
	
	void show(SDL_Surface *screen);
};